
using Microsoft.VisualStudio.TestTools.UnitTesting;

using System.Collections.Generic;

using Weazel.Gezel.Parser;
using Weazel.Gezel.Model;
using Weazel.Gezel.Model.Errors;

namespace Weazel.Gezel.Parser.Test
{
  [TestClass]
  public class TestParseSystem
  {
		[TestMethod]
		public void TestParseSystemStartEndPositions()
		{
			Tokenizer t = new Tokenizer(
				"system s {			\n" +
				"		a(a,b,c);		\n" + 
				"		b(a,b,c);		\n" +
				" }								");

			Model.Model model = new Model.Model("sys");
			ParseSystem.Parse(new Set<Token>(Token.Eof), t, model);
			system s = model.Systems["s"];

			Assert.AreEqual(0, t.Errors.Count);

			Assert.AreEqual<uint>(1, s.StartPosition.LineNumber);
			Assert.AreEqual<uint>(1, s.StartPosition.ColumnNumber);

			Assert.AreEqual<uint>(4, s.EndPosition.LineNumber);
			Assert.AreEqual<uint>(3, s.EndPosition.ColumnNumber);
		}

    [TestMethod]
    public void TestParseSystemSimple()
    {
      Tokenizer t = new Tokenizer("system s {}");

      Model.Model model = new Model.Model("sys");

      ParseSystem.Parse(new Set<Token>(Token.Eof), t, model);

      system s = model.Systems["s"];

      Assert.AreEqual(0, t.Errors.Count);
      Assert.AreEqual("s", s.LocalName);
      Assert.AreEqual(0, s.Stimuli.Count);
			//Assert.AreEqual(0, s.DatapathRefs.Count);
    }

    [TestMethod]
    public void TestParseSystem1()
    {
      Tokenizer t = new Tokenizer("system s { a(a,b,c); b(a,b,c); }");

      Model.Model model = new Model.Model("sys");

      ParseSystem.Parse(new Set<Token>(Token.Eof), t, model);

      system s = model.Systems["s"];

      Assert.AreEqual(0, t.Errors.Count);

      Assert.AreEqual("s", s.LocalName);
      Assert.AreEqual(0, s.Stimuli.Count);
			//Assert.AreEqual(2, s.DatapathRefs.Count);

			//Assert.AreEqual(3, s.DatapathRefs["a"].Length);
			//Assert.AreEqual(3, s.DatapathRefs["b"].Length);

			//Assert.AreEqual("a", s.DatapathRefs["a"][0]);
			//Assert.AreEqual("b", s.DatapathRefs["a"][1]);
			//Assert.AreEqual("c", s.DatapathRefs["a"][2]);

			//Assert.AreEqual("a", s.DatapathRefs["b"][0]);
			//Assert.AreEqual("b", s.DatapathRefs["b"][1]);
			//Assert.AreEqual("c", s.DatapathRefs["b"][2]);
    }

    [TestMethod]
    public void TestParseSystem2()
    {
      Tokenizer t = new Tokenizer("system s { a(a,b,c); stimulus(a, \"my_file\"); }");

      Model.Model model = new Model.Model("sys");

      ParseSystem.Parse(new Set<Token>(Token.Eof), t, model);

      system s = model.Systems["s"];

      Assert.AreEqual(0, t.Errors.Count);

      Assert.AreEqual("s", s.Name);
      Assert.AreEqual(1, s.Stimuli.Count);
			//Assert.AreEqual(1, s.DatapathRefs.Count);

			//Assert.AreEqual(3, s.DatapathRefs["a"].Length);

			//Assert.AreEqual("a", s.DatapathRefs["a"][0]);
			//Assert.AreEqual("b", s.DatapathRefs["a"][1]);
			//Assert.AreEqual("c", s.DatapathRefs["a"][2]);


      Assert.AreEqual("a", s.Stimuli["stimulus0"].SignalRef);
      Assert.AreEqual("my_file", s.Stimuli["stimulus0"].Filename);
    }

		[TestMethod]
		public void TestParseSystemWithNamedBinding1()
		{
			string description =
				"system s {										" +
				" a.port1 = b.port1;		}			"; 
			
			//+
			//  " a.port2 = b.port2;					" +
			//  " a.port3 = portx;						" +
			//  " a.port4 = porty;						" +
			//  " c(portx, porty, a.port5);		" +
			//  "}														";

      Tokenizer t = new Tokenizer(description);

      Model.Model model = new Model.Model("sys");

      ParseSystem.Parse(new Set<Token>(Token.Eof), t, model);

      system s = model.Systems["s"];

			

      Assert.AreEqual(0, t.Errors.Count);
		}
  }
}